#ifndef __FW_INTERFACE_H
#define __FW_INTERFACE_H

#include "drv_inc.h"
#include "mc_type.h"

//test mode
//#define VF_OPENLOOP_MODE
/** PWM interface */
#define SET_CCR1_VAL(Value)         WRITE_REG(TIM1->CCR1, Value)
#define SET_CCR2_VAL(Value)         WRITE_REG(TIM1->CCR2, Value)
#define SET_CCR3_VAL(Value)         WRITE_REG(TIM1->CCR3, Value)
#define SET_CCR4_VAL(Value)         WRITE_REG(TIM1->CCR4, Value)

#define DISABLE_PWMOUT()            CLEAR_BIT(TIM1->BDTR, TIM_BDTR_MOEN)
#define ENABLE_PWMOUT()             SET_BIT(TIM1->BDTR, TIM_BDTR_MOEN)

#define READ_TIM1_UPDATE_FLAG()     READ_BIT(TIM1->SR, TIM_IT_Update)
#define CLEAN_TIM1_UPDATE_FLAG()    CLEAR_BIT(TIM1->SR, TIM_IT_Update)

#define TIM1_BREAK_ENABLE()         SET_BIT(TIM1->BDTR,TIM_BDTR_BKE)
#define TIM1_BREAK_DISABLE()        CLEAR_BIT(TIM1->BDTR,TIM_BDTR_BKE)
#define READ_TIM1_BREAK_FLAG()      READ_BIT(TIM1->SR, TIM_IT_Break)
#define CLEAN_TIM1_BREAK_FLAG()     CLEAR_BIT(TIM1->SR, TIM_IT_Break)

//#define REG_PWM_DUTY1                   TIM1->CCR1
//#define REG_PWM_DUTY2                   TIM1->CCR2
//#define REG_PWM_DUTY3                   TIM1->CCR3
//#define REG_PWM_OUT_ENABLE()            (TIM1->BDTR |= TIM_BDTR_MOE)
//#define REG_PWM_OUT_DISABLE()           (TIM1->BDTR &= (uint16_t)(~((uint16_t)TIM_BDTR_MOE)))


/** ADC interface */
#define GET_ADC1_VALUE(Channel)         (READ_REG(*(&(ADC->CHL##Channel##_RESULT))) & 0xFFF)
//#define GET_ADC1_VALUE(Channel)         (READ_REG(*(&(ADC->CHL0_RESULT) + Channel)) & 0xFFF)

#define REG_ADC_SW_CONV_EN()            (ADC->SQUE0_CFG1 |= ADC_SQUE0_CFG1_SW_TRIG)
#define REG_ADC_CONV_FLAG()             (ADC->SQUE0_CFG1 & ADC_SQUE0_CFG1_QUE_DONE)//(ADC->ISR &  ADC_ISR_EOC_QUE0)//(ADC->SQUE0_CFG1 & ADC_SQUE0_CFG1_QUE_DONE)

#define REG_ADC_SQUE0_FLAG_CLR()         (ADC->SQUE0_CFG1 &= (~(uint32_t)ADC_SQUE0_CFG1_QUE_DONE))



void REG_UpperbridgeIOmode(void);
void REG_UpperbridgePWMmode(void);
void REG_PWM_Output_Ctr(FunctionalState NewState);
void REG_PWM_Duty_Ctr(STR_SVM_TypeDef *tS_SVM);
void REG_PWM_Duty_Output(u16 t_unDuty1, u16 t_unDuty2, u16 t_unDuty3);
void REG_HWDIV_S32Div(STR_DIV_COMP *tS_DIVI);
void REG_PWM_Out_Enable(void);
void REG_PWM_Out_Disable(void);


u16 ADC_Trans_Iu(void);
u16 ADC_Trans_Iv(void);
u16 ADC_Trans_VBus(void);
u16 ADC_Trans_VSP(void);


#endif
/******************* (C) COPYRIGHT 2008 LINKO Semiconductor *****END OF FILE****/
